package com.sykj.huxianlong.controller;



import com.sykj.huxianlong.entity.BxVo;
import com.sykj.huxianlong.entity.ProcessLog;
import com.sykj.huxianlong.entity.TaskVo;
import com.sykj.huxianlong.service.ILogService;
import com.sykj.huxianlong.service.ITaskProceService;
import com.sykj.util.reponse.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/leave")
public class HxlTaskController {


    @Autowired
    private ITaskProceService taskProceService;

    @Autowired
    private ILogService logService;


    /**
     * 查询我的任务
     * @param
     * @return
     */
    @RequestMapping(value= "queryMyTask",method = RequestMethod.GET)
    @ResponseBody
    public List<TaskVo> queryMyTask() {
        List<TaskVo> task = taskProceService.queryMyTask();
        //return ResponseUtil.makeTableRsp(0,taskPage.getTotal(),taskPage.getRecords());
       // return  new ResultBody("10061","查询成功");
        return task;
    }

    /**
     * 查询我的报销任务
     * @param
     * @return
     */
    @RequestMapping(value= "queryMyTaskbx",method = RequestMethod.POST)
    @ResponseBody
    public List<BxVo> queryMyTaskbx() {
        List<BxVo> task = taskProceService.queryMyTaskbx();
        return task;
    }

    /**
     * 流程审批
     * @param taskVo
     * @return
     */
    @PostMapping("completeTask")
    @ResponseBody
    public ResultBody completeTask(@RequestBody TaskVo taskVo) {
        ResultBody resultBody=new ResultBody();

       try{
           taskProceService.completeTask(taskVo);
           resultBody.setCode("10081");
           resultBody.setMessage("成功");
       }
       catch(Exception e){
           resultBody.setCode("10082");
           resultBody.setMessage("失败");
        }
        return resultBody;
    }

    /**
     * 报销流程
     * @param bxVo
     * @return
     */
    @PostMapping("bxcompleteTask")
    @ResponseBody
    public ResultBody completeTask(@RequestBody BxVo bxVo) {
        ResultBody resultBody=new ResultBody();

        try{
            taskProceService.bxcompleteTask(bxVo);
            resultBody.setCode("10091");
            resultBody.setMessage("成功");
        }
        catch(Exception e){
            resultBody.setCode("10092");
            resultBody.setMessage("失败");
        }
        return resultBody;
    }

    /**
     * 审批详情页
     * @param model
     * @param flowId
     * @param orderNo
     * @return
     */
    @RequestMapping( "provalDetail")
    public List<ProcessLog> provalDetail(Model model,@RequestParam("flowId") String flowId,@RequestParam("orderNo") Long orderNo) {
        List<ProcessLog> logList = logService.queryOperLog(orderNo);
        model.addAttribute("logList",logList);
        return logList;
    }
}
